<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="交易分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="category">
              <j-dict-select-tag
                type="list"
                v-model="model.category"
                dictCode="sys_trade_category"
                placeholder="请选择交易分类"
              />
            </a-form-model-item>
          </a-col>
        
          <a-col :span="24">
            <a-form-model-item label="发布区域" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="area">
             <!-- <a-input v-model="model.area" placeholder="请输入发布区域"  ></a-input>-->
              <j-dict-select-tag
                type="list"
                v-model="model.area"
                dictCode="sys_kf_area"
                placeholder="请选择项目所在区域"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="titile">
              <a-input v-model="model.titile" placeholder="请输入标题"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="摘要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="summary">
              <a-input v-model="model.summary" placeholder="请输入摘要"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content">
              <j-editor v-model="model.content" />
            </a-form-model-item>
          </a-col>
          <!--
          <a-col :span="24">
            <a-form-model-item label="打开方式(组件：component 路由：url)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openType">
              <a-input v-model="model.openType" placeholder="请输入打开方式(组件：component 路由：url)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="组件/路由 地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openPage">
              <a-input v-model="model.openPage" placeholder="请输入组件/路由 地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          -->
          <a-col :span="24">
            <a-form-model-item label="优先级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="priority">
              <j-dict-select-tag
                type="list"
                v-model="model.priority"
                dictCode="priority_type"
                placeholder="请选择优先级"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发布状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="publishStatus">
              <j-dict-select-tag
                type="list"
                v-model="model.publishStatus"
                dictCode="web_publish_status"
                placeholder="请选择发布状态"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发布人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="publisher">
              <a-input v-model="model.publisher" placeholder="请输入发布人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发布时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="publishTime">
              <!--<j-date placeholder="请选择发布时间"  value-format="yyyy-MM-dd HH:mm:ss" v-model="model.publishTime"  style="width: 100%" />-->
           <j-date
             placeholder="请选择发布时间"
             v-model="model.publishTime"
             :show-time="true"
             date-format="YYYY-MM-DD HH:mm:ss"
             style="width: 100%">
           </j-date>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'WebTradeNoticeForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          // 设置type的默认值为1
                  type: '1'   //默认设为1代表招标计划公示
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           category: [
              { required: true, message: '请输入分类'},
           ],
           
        },
        url: {
          add: "/website/webTradeNotice/add",
          edit: "/website/webTradeNotice/edit",
          queryById: "/website/webTradeNotice/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>